<template>
  <div class="news-details">
    <p class="title">{{detail.title}}</p>
    <p class="time">{{detail.create_time | formatDate}}</p>
    <div class="con" v-html="detail.content"></div>
  </div>
</template>

<script>
import { getWelfareNewsDetails, getCourseNewsDetails, dynamicDetail } from "@/api/api"
import { formatDate } from '@/util/date.js'
import { commonShare } from "@/config/wxshare"
export default {
  filters:{
      formatDate(time){
        let date = new Date(time*1000);
        return formatDate(date,'yyyy.MM.dd hh:mm');
      }
  },
  components: {
  },
  data () {
    return {
      detail: {},
    }
  },
  created () {
    this.id = this.$route.query.newsId;
    this.type = this.$route.query.type;
    if(this.type == 'welfare'){
      this.getWelfareDetails()
    }else if(this.type == "pro"){
      this.dynamic_detail(); 
    }else{
      this.getDetails();
    }  
  },
  methods: {
    getWelfareDetails() {
      getWelfareNewsDetails(this.id).then((res) => {
        this.detail = res.data.data.info
        commonShare(this.detail.img, '智慧宝新闻', this.detail.title);
      }).catch((err) => {
        console.dir(err)
      })
    },
    getDetails() {
      getCourseNewsDetails(this.id).then((res) => {
        this.detail = res.data.data.info
        commonShare(this.detail.img, '智慧宝新闻', this.detail.title);
      }).catch((err) => {
        console.dir(err)
      })
    },
    dynamic_detail() {
      dynamicDetail(this.id).then((res) => {
        this.detail = res.data.data.info
        commonShare(this.detail.img, '智慧宝新闻', this.detail.title);
      }).catch((err) => {
        console.dir(err)
      })
    }
  }
}
</script>
<style lang="stylus" scoped>
  .news-details
    background-color #fff
    padding 1.5rem
    .title
      line-height 2.4rem
      font-size 1.7rem
      color #333
      font-weight 800
      margin-bottom 1rem
    .time
      font-size 1.2rem
      height 1.2rem
      line-height 1.2rem
      color #999
      margin-bottom 1.5rem
    .cons
      font-size 1.3rem
      line-height 2rem
      color #666
    img
      margin 2rem 0
      display block
</style>